package com.abc.cloud.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.abc.cloud.dto.im.ChatDetail;
import com.abc.cloud.vo.im.AdminUpdateChatDetailReq;
import com.abc.cloud.vo.im.AdminUpdateChatReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.abc.cloud.entity.ChatDetailEntity;
import com.abc.cloud.service.ChatDetailService;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Result;



/**
 * 聊天记录表
 *
 * @author LiJunXi
 * @email 2770063826@qq.com
 * @date 2023-11-29 13:17:40
 */
@Api(tags = "聊天记录接口")
@RestController
@RequestMapping("/chatDetail")
public class ChatDetailController {
    @Autowired
    private ChatDetailService chatDetailService;

    /**
     * 获取用户聊天记录（未读）
     */
    @ApiOperation("获取用户聊天记录（未读）")
    @GetMapping("/list")
    public Result<List<ChatDetail>> list(@RequestParam Map<String, Object> params){

        List<ChatDetail> res = chatDetailService.queryPage(params);

        return Result.success(res, "获取成功");
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		ChatDetailEntity chatDetail = chatDetailService.getById(id);

        return Result.success(chatDetail, "chatDetail");
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody ChatDetailEntity chatDetail){
		chatDetailService.save(chatDetail);

        return Result.success(null, "");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody ChatDetailEntity chatDetail){
		chatDetailService.updateById(chatDetail);

        return Result.success(null, "");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		chatDetailService.removeByIds(Arrays.asList(ids));

        return Result.success(null, "");
    }

    @ApiOperation("管理员分页获取聊天内容列表")
    @GetMapping("/admin/list")
    public Result adminChatDetailList(@RequestParam Map<String, Object> params){
        PageUtil page = chatDetailService.adminChatList(params);

        return Result.success(page, "获取成功");
    }

    @ApiOperation("管理员修改聊天内容信息")
    @PutMapping("/admin/update")
    public Result adminUpdateChatDetail(@RequestBody AdminUpdateChatDetailReq adminUpdateChatDetailReq){
        chatDetailService.adminUpdateChat(adminUpdateChatDetailReq);

        return Result.success(null, "操作成功");
    }

    @ApiOperation("管理员批量修改聊天内容状态")
    @PutMapping("/admin/updateStatus/{status}")
    public Result adminDeleteChatDetail(@RequestBody List<Long> ids,
                                  @PathVariable("status") Integer status){
        chatDetailService.adminDeleteChat(ids, status);

        return Result.success(null, "操作成功");
    }

}
